<%@page isErrorPage="true" %>

<%@page session="false" %>

<%@page import="java.io.Writer"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.StringWriter"%>
<%@page import="org.apache.log4j.Logger"%>


<%!
  public final static Logger log = Logger.getLogger("fallback-error.jsp");

  public static String getStackTraceAsString(final Throwable t) {
    final Writer result = new StringWriter();

    t.printStackTrace( new PrintWriter( result ) );
    
    return result.toString();
  }  
%>

<h1>An error occured in the normal error page!</h1>
<p>May not have been able to log the error. Were not able to show the normal error page.</p>
<%
  try {
%>
<pre>
<%= getStackTraceAsString(exception) %>
</pre>
<%
  } catch(Throwable t) {
%>
  An exception occured on the error fallback page when original exception was about to be printed: <%= t %>
  <p>
  Original exception: <%= exception %>
<%
  }

  try {
    log.error("Error in the fancy error page. Falling back on basic error-page: ", exception);
  } catch(Throwable t) {
%>
  An exception occured when the fallback error page tried to log the original exception with log4j: <%= t %>
<%
  }
%>